<!doctype html>
<html lang="zh-CN">
<head>
  <base href="https://www.nodeapp.cn/globals.html" />
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>全局对象 | Node.js 中文文档 | Node.js 中文网</title>
  <meta name="description" content="Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境。Node.js 使用了一个事件驱动、非阻塞式 I/O 的模型，使其轻量又高效。Node.js 的包管理器 npm，是全球最大的开源库生态系统。">
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="https://www.nodeapp.cn/globals.html">
  <link rel="apple-touch-icon" href="apple-touch-icon.png">
  <link rel="icon" sizes="32x32" type="image/png" href="favicon.png">
  
  <script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?acdf78480f7f8f2b23b812565a5868e0";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</head>
<body class="alt apidoc" id="api-section-globals">
  <div id="content" class="clearfix">
    <div id="column1" data-id="globals" class="interior">
      <header>
        <h1>Node.js v8.x 中文文档</h1>
        <hr>
      </header>

      <div id="toc">
        <h2>目录</h2>
        <ul>
<li><span class="stability_undefined"><a href="#globals_global_objects">global - 全局变量</a></span><ul>
<li><span class="stability_undefined"><a href="#globals_class_buffer">Buffer</a></span></li>
<li><span class="stability_undefined"><a href="#globals_dirname">__dirname</a></span></li>
<li><span class="stability_undefined"><a href="#globals_filename">__filename</a></span></li>
<li><span class="stability_undefined"><a href="#globals_clearimmediate_immediateobject">clearImmediate(immediateObject)</a></span></li>
<li><span class="stability_undefined"><a href="#globals_clearinterval_intervalobject">clearInterval(intervalObject)</a></span></li>
<li><span class="stability_undefined"><a href="#globals_cleartimeout_timeoutobject">clearTimeout(timeoutObject)</a></span></li>
<li><span class="stability_undefined"><a href="#globals_console">console</a></span></li>
<li><span class="stability_undefined"><a href="#globals_exports">exports</a></span></li>
<li><span class="stability_undefined"><a href="#globals_global">global</a></span></li>
<li><span class="stability_undefined"><a href="#globals_module">module</a></span></li>
<li><span class="stability_undefined"><a href="#globals_process">process</a></span></li>
<li><span class="stability_undefined"><a href="#globals_require">require()</a></span></li>
<li><span class="stability_undefined"><a href="#globals_setimmediate_callback_args">setImmediate(callback[, ...args])</a></span></li>
<li><span class="stability_undefined"><a href="#globals_setinterval_callback_delay_args">setInterval(callback, delay[, ...args])</a></span></li>
<li><span class="stability_undefined"><a href="#globals_settimeout_callback_delay_args">setTimeout(callback, delay[, ...args])</a></span></li>
</ul>
</li>
</ul>

      </div>
<div id="apicontent">
        <h1>global - 全局变量<span><a class="mark" href="#globals_global_objects" id="globals_global_objects">#</a></span></h1>
<!--introduced_in=v0.10.0-->
<!-- type=misc -->
<p>全局变量在所有模块中均可使用。
但以下变量的作用域只在模块内，详见 <a href="modules.html">module文档</a>：</p>
<ul>
<li><a href="modules.html#modules_dirname"><code>__dirname</code></a></li>
<li><a href="modules.html#modules_filename"><code>__filename</code></a></li>
<li><a href="modules.html#modules_exports"><code>exports</code></a></li>
<li><a href="modules.html#modules_module"><code>module</code></a></li>
<li><a href="modules.html#modules_require"><code>require()</code></a></li>
</ul>
<p>以下的对象是特定于 Node.js 的。
有些<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects">内置对象</a>是 JavaScript 语言本身的一部分，它们也是全局的。</p>
<h2>Buffer<span><a class="mark" href="#globals_class_buffer" id="globals_class_buffer">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.1.103</span>
</div><!-- type=global -->
<ul>
<li>
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>用于处理二进制数据。详见 <a href="buffer.html">buffer文档</a>。</p>
<h2>__dirname<span><a class="mark" href="#globals_dirname" id="globals_dirname">#</a></span></h2>
<p>详见 <a href="modules.html#modules_dirname"><code>__dirname</code></a> 文档。</p>
<h2>__filename<span><a class="mark" href="#globals_filename" id="globals_filename">#</a></span></h2>
<p>详见 <a href="modules.html#modules_filename"><code>__filename</code></a> 文档。</p>
<h2>clearImmediate(immediateObject)<span><a class="mark" href="#globals_clearimmediate_immediateobject" id="globals_clearimmediate_immediateobject">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.9.1</span>
</div><!--type=global-->
<p>详见 <a href="timers.html#timers_clearimmediate_immediate"><code>clearImmediate</code></a> 文档。</p>
<h2>clearInterval(intervalObject)<span><a class="mark" href="#globals_clearinterval_intervalobject" id="globals_clearinterval_intervalobject">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.0.1</span>
</div><!--type=global-->
<p>详见 <a href="timers.html#timers_clearinterval_timeout"><code>clearInterval</code></a> 文档。</p>
<h2>clearTimeout(timeoutObject)<span><a class="mark" href="#globals_cleartimeout_timeoutobject" id="globals_cleartimeout_timeoutobject">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.0.1</span>
</div><!--type=global-->
<p>详见 <a href="timers.html#timers_cleartimeout_timeout"><code>clearTimeout</code></a> 文档。</p>
<h2>console<span><a class="mark" href="#globals_console" id="globals_console">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.1.100</span>
</div><!-- type=global -->
<ul>
<li>
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>用于打印 <code>stdout</code> 和 <code>stderr</code>。
详见 <a href="console.html"><code>console</code></a> 文档。</p>
<h2>exports<span><a class="mark" href="#globals_exports" id="globals_exports">#</a></span></h2>
<p>详见 <a href="modules.html#modules_exports"><code>exports</code></a> 文档。</p>
<h2>global<span><a class="mark" href="#globals_global" id="globals_global">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.1.27</span>
</div><!-- type=global -->
<ul>
<li>
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> 全局的命名空间对象。</li>
</ul>
<p>在浏览器中，顶层作用域就是全局作用域。
这意味着在浏览器中，<code>var something</code> 会定义一个新的全局变量。
在 Node.js 中则不同，顶层作用域不是全局作用域，<code>var something</code> 的作用域只在模块内。</p>
<h2>module<span><a class="mark" href="#globals_module" id="globals_module">#</a></span></h2>
<p>详见 <a href="modules.html#modules_module"><code>module</code></a> 文档。</p>
<h2>process<span><a class="mark" href="#globals_process" id="globals_process">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.1.7</span>
</div><!-- type=global -->
<ul>
<li>
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>进程对象。
详见 <a href="process.html#process_process"><code>process</code></a> 文档。</p>
<h2>require()<span><a class="mark" href="#globals_require" id="globals_require">#</a></span></h2>
<p>详见 <a href="modules.html#modules_require"><code>require()</code></a> 文档。</p>
<h2>setImmediate(callback[, ...args])<span><a class="mark" href="#globals_setimmediate_callback_args" id="globals_setimmediate_callback_args">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.9.1</span>
</div><!-- type=global -->
<p>详见 <a href="timers.html#timers_setimmediate_callback_args"><code>setImmediate</code></a> 文档。</p>
<h2>setInterval(callback, delay[, ...args])<span><a class="mark" href="#globals_setinterval_callback_delay_args" id="globals_setinterval_callback_delay_args">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.0.1</span>
</div><!-- type=global -->
<p>详见 <a href="timers.html#timers_setinterval_callback_delay_args"><code>setInterval</code></a> 文档。</p>
<h2>setTimeout(callback, delay[, ...args])<span><a class="mark" href="#globals_settimeout_callback_delay_args" id="globals_settimeout_callback_delay_args">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.0.1</span>
</div><!-- type=global -->
<p>详见 <a href="timers.html#timers_settimeout_callback_delay_args"><code>setTimeout</code></a> 文档。</p>

      </div>
    </div>

    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="/" title="Go back to the home page">
          Node.js 中文文档 | Node.js 中文网
        </a>
      </div>
      
        <!-- [start-include:_toc.md] -->
<ul>
<li><a href="documentation.html">关于本文档</a></li>
<li><a href="synopsis.html">用法与例子</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a href="assert.html">断言测试</a></li>
<li><a href="async_hooks.html">异步钩子（Async Hooks）</a></li>
<li><a href="buffer.html">缓存（Buffer）</a></li>
<li><a href="addons.html">C++ 插件</a></li>
<li><a href="n-api.html">C/C++ 插件 - N-API</a></li>
<li><a href="child_process.html">子进程</a></li>
<li><a href="cluster.html">集群（Cluster）</a></li>
<li><a href="cli.html">命令行参数</a></li>
<li><a href="console.html">控制台（Console）</a></li>
<li><a href="crypto.html">加密（Crypto）</a></li>
<li><a href="debugger.html">调试器</a></li>
<li><a href="deprecations.html">废弃的 API</a></li>
<li><a href="dns.html">DNS</a></li>
<li><a href="domain.html">域（Domain）</a></li>
<li><a href="esm.html">ECMAScript 模块</a></li>
<li><a href="errors.html">错误（Errors）</a></li>
<li><a href="events.html">事件（Events）</a></li>
<li><a href="fs.html">文件系统</a></li>
<li><a href="globals.html">全局对象（Globals）</a></li>
<li><a href="http.html">HTTP</a></li>
<li><a href="http2.html">HTTP/2</a></li>
<li><a href="https.html">HTTPS</a></li>
<li><a href="inspector.html">检查工具（Inspector）</a></li>
<li><a href="intl.html">国际化</a></li>
<li><a href="modules.html">模块（Modules）</a></li>
<li><a href="net.html">网络（Net）</a></li>
<li><a href="os.html">操作系统（OS）</a></li>
<li><a href="path.html">路径（Path）</a></li>
<li><a href="perf_hooks.html">性能钩子（Performance Hooks）</a></li>
<li><a href="process.html">进程</a></li>
<li><a href="punycode.html">Punycode</a></li>
<li><a href="querystring.html">查询字符串</a></li>
<li><a href="readline.html">逐行读取</a></li>
<li><a href="repl.html">交互式解释器（REPL）</a></li>
<li><a href="stream.html">流（Stream）</a></li>
<li><a href="string_decoder.html">字符串解码</a></li>
<li><a href="timers.html">定时器（Timers）</a></li>
<li><a href="tls.html">安全传输层（TLS/SSL）</a></li>
<li><a href="tracing.html">事件跟踪（Tracing）</a></li>
<li><a href="tty.html">TTY</a></li>
<li><a href="dgram.html">UDP / 数据报</a></li>
<li><a href="url.html">URL</a></li>
<li><a href="util.html">工具集</a></li>
<li><a href="v8.html">V8</a></li>
<li><a href="vm.html">虚拟机（VM）</a></li>
<li><a href="zlib.html">压缩（ZLIB）</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a href="https://github.com/nodejs/node">GitHub 仓库和问题跟踪</a></li>
<li><a href="https://groups.google.com/group/nodejs">邮件列表</a></li>
</ul>
<!-- [end-include:_toc.md] -->

      
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
</body>
</html>
